package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {

	file := "1.txt"
	f, err := os.Open(file)
	if err != nil {
		fmt.Println("open file failed:", err)
		return
	}
	defer f.Close()
	bio := bufio.NewReaderSize(f, 64)
	fmt.Printf("初始状态缓冲区缓存的数据总量为 %d字节\n", bio.Buffered())

	var i int = 1
	for {
		data := make([]byte, 5)
		n, err := bio.Read(data)
		if err == io.EOF {
			fmt.Println("meet file EOF")
			return
		}
		if err != nil {
			fmt.Println("read file failed:", err)
			return
		}
		fmt.Printf("第 %d 次读取数据：%q, 长度=%d\n", i, data, n)
		fmt.Printf("当前缓冲区缓存的数据总量为 %d字节\n", bio.Buffered())
		i++

	}

}
